<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>vue-router 讲解</title>
    <script src="https://unpkg.com/vue/dist/vue.js"></script>
    <script src="https://unpkg.com/vue-router/dist/vue-router.js"></script>
</head>

<body>
    <h3>动态路由匹配 props 2</h3>
    <div id="app">
        <router-link to="/user/1">User1</router-link>
        <router-link to="/user/2">User2</router-link>
        <router-link to="/user/3">User3</router-link>
        <router-link to="/register">Register</router-link>
        <!-- 路由对应的 View 在这里显示 -->
        <router-view style="margin-top: 10px;">

        </router-view>
    </div>
    <script>
        const User = {
            props: ['id', 'uname', 'age'],
            template: '<h1>User 组件 -- 用户id:{{id}} 姓名:{{uname}} 年龄:{{age}}</h1>'
        }
        const Register = {
            template: '<h1>Register 组件</h1>'
        }
        //声明路由规则
        const routes = [
            {
                //路由重定向
                path: '/', redirect: '/user'
            },
            {
                path: '/user/:id', component: User, props: { uname: 'lishi', age: 20 }
            },
            {
                path: '/register', component: Register
            }
        ]
        //创建 router 实例
        const router = new VueRouter({
            routes //就相当于是 routes:routes
        })
        var vm = new Vue({
            //指定控制的区域
            el: '#app',
            router: router
        })
    </script>

</body>

</html>